﻿using Rabbit.Contracts.Interface;
using Rabbit.Domain.Entity;
using Rabbit.Domain.IRepository;
using Rabbit.Domain.OutDTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rabbit.Service
{
    public class GoodInfoService : IGoodInfoService
    {
        private readonly IGoodInfoRepository _goodInfoRepository;
        private readonly IGoodsRepository _goodsRepository;
        public GoodInfoService(IGoodInfoRepository goodInfoRepository, IGoodsRepository goodsRepository)
        {
            _goodInfoRepository = goodInfoRepository;
            _goodsRepository = goodsRepository;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int GetDelGoodInfo(int id)
        {
            return _goodInfoRepository.GetDelGoodInfo(id); 
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public dynamic GetFindGoodinfo(int id)
        {
            return _goodInfoRepository.GetFindGoodinfo(id);
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="good"></param>
        /// <returns></returns>
        public int GetGoodInfoAdd(Goodinfo good)
        {
            return _goodInfoRepository.GetGoodInfoAdd(good);
           
        }

        /// <summary>
        /// 跳转页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public dynamic GetGoodInfoImage(int id)
        {
            var list = (from a in _goodInfoRepository.GetGoodInfoList()
                        join b in _goodsRepository.GetGoods()
                        on a.GoodId equals b.GoodId
                        where a.GoodInfoId == id && a.IsDel==0
                        select new GoodInfoDTO
                        {
                            IsDel = a.IsDel,
                            CreateName = a.CreateName,
                            GoodCompany = a.GoodCompany,
                            Batch = a.Batch,
                            CreateTime = DateTime.Now,
                            GoodImages = a.GoodImages,
                            GoodName = b.GoodName,
                            Information = a.Information,
                            Production = a.Production,
                            Shelflife = a.Shelflife,
                            UpdateName = a.UpdateName,
                            GoodInfoId = a.GoodInfoId,
                        }).FirstOrDefault();
            return list;
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public List<GoodInfoDTO> GetGoodInfoListss()
        {
            var list=(from a in _goodInfoRepository.GetGoodInfoList()
                     join b in _goodsRepository.GetGoods()
                     on a.GoodId equals b.GoodId
                     where a.IsDel==00
                     select new GoodInfoDTO
                     {
                         IsDel = a.IsDel,
                         CreateName = a.CreateName,
                         GoodCompany = a.GoodCompany,
                         Batch = a.Batch,
                         CreateTime = DateTime.Now,
                         GoodImages = a.GoodImages,
                         GoodName = b.GoodName,
                         Information = a.Information,
                         Production = a.Production,
                         Shelflife = a.Shelflife,
                         UpdateName = a.UpdateName,
                         GoodInfoId = a.GoodInfoId,
                     }).ToList();
            return list;
           //return _goodInfoRepository.GetGoodInfoList();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="good"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int GetGoodInfoUpdate(Goodinfo good)
        {
            return _goodInfoRepository.GetGoodInfoUpdate(good);
        }
    }
}
